package br.univas.vperiod.jowey.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import br.univas.vperiod.jowey.dao.IPlayerJobDAO;
import br.univas.vperiod.jowey.dao.IProjectDAO;
import br.univas.vperiod.jowey.entities.Player;
import br.univas.vperiod.jowey.entities.PlayerJob;
import br.univas.vperiod.jowey.entities.Project;

@Controller
@RequestMapping("project")
public class ProjectController {
	
	@Autowired
	private IProjectDAO<?> projectDao;
	
	@Autowired
	private IPlayerJobDAO<?> playerJobDao;
	
	@RequestMapping("/list")
	public String list(){
		return "project";
	}
	
	@RequestMapping(value="/getProjects",method = RequestMethod.GET)
	@ResponseBody
	public ArrayList<Project> getProjects(){
		
		ArrayList<Project> projectsNew = projectDao.findAll();
				
		for (Project iter : projectsNew) {
    		iter.setPlayerJobs(null);
		}
		
		return  projectsNew;
	}
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	@ResponseBody
	public Project saveContact(Project project){
		projectDao.save(project);
		return project;
	}
	
}
